package com.aiguigu.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CASHello {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(10);
        System.out.println(atomicInteger.get());

//        System.out.println(atomicInteger.compareAndSet(10, 20)+"\t"+atomicInteger.get());
//        System.out.println(atomicInteger.compareAndSet(10, 25)+"\t"+atomicInteger.get());
//
//        System.out.println(atomicInteger.incrementAndGet()+"\t"+atomicInteger.get()); //i++
//        System.out.println(atomicInteger.getAndIncrement()+"\t"+atomicInteger.get()); //i++
//
//        System.out.println(atomicInteger.decrementAndGet()+"\t"+atomicInteger.get());//--i
//        System.out.println(atomicInteger.getAndDecrement()+"\t"+atomicInteger.get());//i--
//
//
//        System.out.println(atomicInteger.getAndSet(30)+"\t"+atomicInteger.get());
        System.out.println("====================");
//        System.out.println(atomicInteger.compareAndSet(10, 30)+"\t"+atomicInteger.get());
//        System.out.println(atomicInteger.compareAndSet(10, 50)+"\t"+atomicInteger.get());

        System.out.println(atomicInteger.addAndGet(5)+"\t"+atomicInteger.get());//先加获取
        System.out.println(atomicInteger.getAndAdd(5)+"\t"+atomicInteger.get());//先获取再加

    }
}
